home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Cuadros de diálogo / DrawOrFillEllipse / ColorFillDialogBox.cs next >
Encoding:
Text File  |  2002-05-23  |  3.4 KB  |  102 lines

  1. //-------------------------------------------------
  2. // ColorFillDialogBox.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class ColorFillDialogBox: Form
  9. {
  10.      protected GroupBox grpbox;
  11.      protected CheckBox chkbox;
  12.  
  13.      public ColorFillDialogBox()
  14.      {
  15.           Text = "Seleccionar color y relleno";
  16.  
  17.           FormBorderStyle = FormBorderStyle.FixedDialog;
  18.           ControlBox      = false;
  19.           MinimizeBox     = false;
  20.           MaximizeBox     = false;
  21.           ShowInTaskbar   = false;
  22.           Location        = ActiveForm.Location + 
  23.                             SystemInformation.CaptionButtonSize +
  24.                             SystemInformation.FrameBorderSize;
  25.  
  26.           string[] astrColor = { "Black", "Blue", "Green", "Cyan",   
  27.                                  "Red", "Magenta", "Yellow", "White"};
  28.  
  29.           grpbox = new GroupBox();
  30.           grpbox.Parent   = this;
  31.           grpbox.Text     = "Color";
  32.           grpbox.Location = new Point(8, 8);
  33.           grpbox.Size     = new Size(96, 12 * (astrColor.Length + 1));
  34.  
  35.           for (int i = 0; i < astrColor.Length; i++)
  36.           {
  37.                RadioButton radiobtn = new RadioButton();
  38.                radiobtn.Parent      = grpbox;
  39.                radiobtn.Text        = astrColor[i];
  40.                radiobtn.Location    = new Point(8, 12 * (i + 1));
  41.                radiobtn.Size        = new Size(80, 10);
  42.           }
  43.           chkbox = new CheckBox();
  44.           chkbox.Parent   = this;
  45.           chkbox.Text     = "Rellenar elipse";
  46.           chkbox.Location = new Point(8, grpbox.Bottom + 4);
  47.           chkbox.Size     = new Size(80, 10);
  48.  
  49.           Button btn   = new Button();
  50.           btn.Parent   = this;
  51.           btn.Text     = "Aceptar";
  52.           btn.Location = new Point(8, chkbox.Bottom + 4);
  53.           btn.Size     = new Size(40, 16);
  54.           btn.DialogResult = DialogResult.OK;
  55.           AcceptButton = btn;
  56.  
  57.           btn  = new Button();
  58.           btn.Parent   = this;
  59.           btn.Text     = "Cancelar";
  60.           btn.Location = new Point(64, chkbox.Bottom + 4);
  61.           btn.Size     = new Size(44, 16);
  62.           btn.DialogResult = DialogResult.Cancel;
  63.           CancelButton = btn;
  64.  
  65.           ClientSize = new Size(118, btn.Bottom + 8);
  66.           AutoScaleBaseSize = new Size(4, 8);
  67.      }
  68.      public Color Color
  69.      {
  70.           get 
  71.           { 
  72.                for (int i = 0; i < grpbox.Controls.Count; i++)
  73.                {
  74.                     RadioButton radiobtn = (RadioButton) grpbox.Controls[i];
  75.  
  76.                     if (radiobtn.Checked)
  77.                          return Color.FromName(radiobtn.Text);
  78.                }
  79.                return Color.Black;
  80.                
  81.           }  
  82.           set 
  83.           { 
  84.                for (int i = 0; i < grpbox.Controls.Count; i++)
  85.                {
  86.                     RadioButton radiobtn = (RadioButton) grpbox.Controls[i];
  87.  
  88.                     if (value == Color.FromName(radiobtn.Text))
  89.                     {
  90.                          radiobtn.Checked = true;
  91.                          break;
  92.                     }
  93.                }
  94.           }
  95.      }
  96.      public bool Fill
  97.      {
  98.           get { return chkbox.Checked; }
  99.           set { chkbox.Checked = value; }
  100.      }
  101. }
  102.